
#include "LogExecutor.h"

#include <string>
#include <sstream>
using namespace std;

namespace Utility
{
		namespace LoggerLib
		{
            LoggingEvent::LoggingEvent(const wstring& strMessage, ELOGLEVEL eLevel, unsigned long dwModule)
                : message(strMessage), level(eLevel), dwModule(dwModule)
            {
                GetLocalTime(&st);
            }

            LoggingEvent::~LoggingEvent()
            {

            }

            wstring LoggingEvent::GetLevelString(ELOGLEVEL level)
            {
                wstring strLevel;
                switch(level)
                {
                case ALL_LEVEL:
                    strLevel = L"ALL";
                    break;
                case DEBUG_LEVEL:
                    strLevel = L"DEBUG";
                    break;
                case ERROR_LEVEL:
                    strLevel = L"ERROR";
                    break;
                case WARN_LEVEL:
                    strLevel = L"WARN";
                    break;
                case INFO_LEVEL:
                    strLevel = L"INFO";
                    break;
                default:
                    break;
                }

                return strLevel;
            }

            wstring LoggingEvent::Format() const
            {
                TCHAR tszError[MAX_PATH] = {0};
                wstring strLevel = GetLevelString(level);

                _snwprintf_s(tszError, MAX_PATH, _TRUNCATE, L"%04d-%02d-%02d %02d:%02d:%02d:%04d %s %ld %s", st.wYear, st.wMonth, st.wDay,
                    st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, strLevel.c_str(), dwModule, message.c_str());

                return tszError;
            }

            wstring LoggingEvent::FormatWithoutTime() const
            {
                TCHAR tszError[MAX_PATH] = {0};
                wstring strLevel = GetLevelString(level);

                _snwprintf_s(tszError, MAX_PATH, _TRUNCATE, L"%s %ld %s", strLevel.c_str(), dwModule, message.c_str());

                return tszError;
            }

			IExecutor::IExecutor(const wstring& strName)
			{
				m_strName = strName;
			}

			IExecutor::~IExecutor(void)
			{
			}
		} // namespace Logger
} // namespace Utility